<{include file="www/header.tpl"}>
<{include file="www/header-base.tpl"}>

<h2 class="base-title"><{$data.msg}>！</h2>

<form action="/homepage/save_pwd" method="post" id="pwd" class="forget-pwd">

    <label class="label fix">
        <span class="span">&nbsp;&nbsp;&nbsp;新密码</span>
        <input type="password" name="password" placeholder="新密码" class="mail">
    </label>

    <label class="label fix">
        <span class="span">确认密码</span>
        <input type="password"  name="password2" placeholder="确认密码"  class="mail">
    </label>

    <input type="hidden" name="token" value="<{$data.token}>"/>
    <input type="button" id="reset_pwd_btn" value="修改密码" class="submit">
</form>

<script>
    $(function(){
        var form = $("#pwd");
        var btn = $("#reset_pwd_btn");
        var passwd = $("input[name='password']");
        var repasswd = $("input[name='password2']");
        var email = $("input[name='token']");
        repasswd.blur(function(){
            check_pwd();
        });

        btn.click(function(){
            if(check_pwd()) {
                $.post('/homepage/save_pwd', { password: passwd.val(),token:email.val() }, function (text, status) {
                        var obj = JSON.parse(text);
                    console.log(obj);
                        if(obj.status == 0){
                            layer.msg(obj.msg);
                            setTimeout(function (){
                                location.href = '/';
                            }, 2000);
                            return false;
                        }else{
                            layer.msg(obj.msg);
                            return false;
                        }
                });
            }
        });

        function check_pwd(){
            if(passwd.val()  == "" ){
                layer.msg("密码不能为空");
                return false;
            }
            if(repasswd.val() == ""){
                layer.msg("请填写确认密码");
                return false;
            }
            if(passwd.val() != repasswd.val() ){
                layer.msg("两次密码不一致");
                return false;
            }
            return true;
        }
    });



</script>
<{include file="www/footer.tpl"}>
